package hrc.tool;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Random;

/**
 * a class have only static function which used to get time or get a unique id base on time
 * @author hrc
 *
 */
public class TimeUnit {

	public static String getCurrentTime(String timeForm) {
		return new SimpleDateFormat(timeForm).format(new Date());
	}

	public static String getCurrentTime() {
		return String.valueOf(new Date().getTime());
	}

	public static String getUniqueName(int range) {
		return getCurrentTime()
				+ String.valueOf(new Random().nextInt(range) + range);
	}

	public static int getRandom(int range) {
		return new Random().nextInt(range) + range;
	}

	public static boolean isDate(String str) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			dateFormat.parse(str);
			return true;
		} catch (Exception e) {
			return false;
		}

	}

}
